package com.qdu.mapper;

import com.qdu.bean.RentCarBean;
import com.qdu.bean.bikeWritable;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class CountByYearMapper extends Mapper<LongWritable, Text, bikeWritable, RentCarBean> {
    bikeWritable bw=new bikeWritable();
    RentCarBean rc= new RentCarBean();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] data = line.split(",");
        String[] datetime = data[0].split(" ");
        String[] date = datetime[0].split("/");
        int casual=Integer.parseInt(data[9]);
        int registered=Integer.parseInt(data[10]);
        int count=Integer.parseInt(data[11]);
        bw.set1(date[0]+"-"+date[1]);
        rc.set1(casual,registered,count);
        context.write(bw,rc);
    }
}
